package cn.unknownerror.ueteam.team;

import cn.unknownerror.ueteam.data.Data;

import java.util.List;
import java.util.UUID;

/**
 * 实现Team接口里面基础功能的抽象类
 * 用作扩展队伍类型的模板。
 */
public abstract class AbstractTeam implements ITeam {
    private AbstractTeamMeta meta ;

    AbstractTeam(String _name, int _maxMember, UUID _captain) throws TeamException {
        meta = new AbstractTeamMeta(_name,_maxMember,_captain,this);
    }
    AbstractTeam(AbstractTeamMeta _meta){
        meta=_meta;
    }
    AbstractTeam(Data data) throws TeamException {
        meta=new AbstractTeamMeta(data,this);
    }

    public int getMaxmember() {
        return meta.getMaxmember();
    }

    public void setMaxmember(int i) throws TeamException {
        meta.setMaxmember(i);
    }

    public UUID getCaptain() {
        return meta.getCaptain();
    }

    public void removeMember(UUID uuid) {
        if(uuid.equals(getCaptain())) dissolve();
        meta.removeMember(uuid);
    }

    public boolean addMember(UUID uuid) {
        return meta.addMember(uuid);
    }

    public List<UUID> getMembers() {
        return meta.getMembers();
    }

    public void setMembers(List<UUID> list) throws TeamException {
        meta.setMembers(list);
        if(!hasMember(getCaptain())) dissolve();
    }

    public boolean hasMember(UUID uuid) {
        return meta.hasMember(uuid);
    }

    public String getName() {
        return meta.getName();
    }

    public void setName(String _name) {
        meta.setName(_name);
    }

    public UUID getUUID(){
        return meta.getUUID();
    }

    public boolean getTeamState() {
        return meta.getTeamState();
    }

    public void setTeamState(boolean state) {
        meta.setTeamState(state);
    }

    /**
     * 解散这支队伍。
     */
    public abstract void dissolve();

    public abstract boolean isDissolve();


    public AbstractTeamMeta getMeta(){
        return meta;
    }
}
